/**
 * 反馈表
 * Aaron create by 2019/06/14
 */
import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  OneToMany,
  UpdateDateColumn,
} from 'typeorm';
import moment = require('moment');
import { Orders } from './order.entity';

@Entity()
export class Goods {
  @PrimaryGeneratedColumn({
    comment: '自增ID',
  })
  id: number;

  @OneToMany((type) => Orders, (Orders) => Orders.goods)
  orders: Orders[];

  @Column({
    nullable: false,
    comment: '商品名称',
  })
  name: string;

  @Column({
    type: 'decimal',
    nullable: true,
    comment: '商品价格',
    precision: 7,
    scale: 2,
  })
  price: number;

  @Column({
    nullable: false,
    default: 0,
    comment: '销售数量',
  })
  salesNumber: number;

  @Column({
    nullable: true,
    comment: '商品详情',
    type: 'text',
  })
  infoCode: string;

  @Column({
    nullable: false,
    comment: '包年vip商品',
    default: false,
  })
  isYearVip: boolean;

  @Column({
    nullable: true,
    comment: '包年时间（单位月）',
    default: 0,
  })
  yearVipTime: number;

  @Column({
    nullable: false,
    comment: '短信报警商品',
    default: false,
  })
  isSms: boolean;

  @Column({
    nullable: true,
    comment: '短信充值金额',
    default: 0,
  })
  smsNumber: number;

  @Column({
    nullable: false,
    comment: '电话报警商品',
    default: false,
  })
  isPhone: boolean;

  @Column({
    nullable: true,
    comment: '电话充值金额',
    default: 0,
  })
  phoneNumber: number;

  @Column({
    nullable: false,
    comment: '是否停用',
    default: false,
  })
  isStop: boolean;

  @Column({
    nullable: false,
    comment: '是否删除',
    default: false,
  })
  isDel: boolean;

  @CreateDateColumn({
    type: 'timestamp',
    nullable: false,
    comment: '创建时间',
    update: false,
    transformer: {
      to: (value) => {
        return value;
      },
      from: (value) => {
        return moment(value).format('YYYY-MM-DD HH:mm:ss');
      },
    },
  })
  creatTime: Date;

  @UpdateDateColumn({
    type: 'timestamp',
    nullable: false,
    comment: '更新时间',
    update: true,
    transformer: {
      to: (value) => {
        return value;
      },
      from: (value) => {
        return moment(value).format('YYYY-MM-DD HH:mm:ss');
      },
    },
  })
  updateTime: Date;
}
